<!DOCTYPE html>

<!-- 
The simplest example for the click to call functionality.
This is good as a start point for developers, explaining the basic requirement for a click to call button.
Check the "click2call.html" in the root folder if you are looking for a more complete click 2 call implementation.

You can also start click2call from an url:
http://www.yourwebsite.com/webphonedir/samples/click2call_example.html?wp_serveraddress=YOURSIPDOMAIN&wp_username=USERNAME&wp_password=PASSWORD&wp_md5=MD5AUTH&wp_callto=CALLEDNUMBER
-->

<html>
<head>
    <meta charset="utf-8" />
    <title>Click2Call Basic Example</title>
    
    <script src="../webphone_api.js?jscodeversion=338"></script>
    <script>
        /**Configuration parameters*/
        webphone_api.parameters['serveraddress'] = '';             // yoursipdomain.com your VoIP server IP address or domain name
        webphone_api.parameters['username'] = '';      // SIP account username
        webphone_api.parameters['password'] = '';      // SIP account password (see the "Parameters encryption" in the documentation)        
        webphone_api.parameters['callto'] = '';        // destination number to call
        webphone_api.parameters['autoaction'] = 0;     // 0=nothing (default), 1=call, 2=chat, 3=video call
        webphone_api.parameters['autostart'] = false;     // start the webphone only when button is clicked
    </script>
</head>
<body style="margin: 0; font-family: Verdana ; font-size: 12px; color:#2e3d47;">
    <div style="font-family: Verdana ; font-size: 16px; color:#4eaaec; text-align:center">Click to call</div><br><br>

    <span id="demo_text">This is a demonstration of the simplest click to call functionality of the webphone.<br /></span><br />

    <button id="button_click2call" style="width: 6em;">Call</button>
    <script>
        var btnc2c = document.getElementById("button_click2call");
        if(btnc2c.addEventListener){
            btnc2c.addEventListener("click", function() { ButtonOnclick(); }, false);
        }else if(btnc2c.attachEvent){
            button.attachEvent("onclick", function() { ButtonOnclick(); });
        }
        
        function ButtonOnclick()
        {
            if (webphone_api.isincall() === true){
                webphone_api.hangup();
            }else{
                webphone_api.call(webphone_api.parameters['callto']);
            }
        }
        
        webphone_api.onCallStateChange(function (status, direction, peername, peerdisplayname, line)
        {
            if (status === 'callSetup')
            {
                btnc2c.innerHTML = 'Hangup';
            }
            else if (status === 'callDisconnected')
            {
                btnc2c.innerHTML = 'Call';
            }
        });
    </script>
</body>
</html>
